#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>

#define NUMPTHREAD 10
#define MAXLISTA 15

typedef struct {
	pthread_cond_t can;
	pthread_cond_t read;
	pthread_cond_t update;
	int elements[MAXLISTA];
	int tWait[NUMPTHREAD];
} List;

void initializeList(List *list) {
	printf("Inicializacion Lista\n");
	int i = 0;
	for (i = 0; i < MAXLISTA; i++) {
		(*list).elements[i] = generateRandom();
	}
	for (i = 0; i < NUMPTHREAD; i++) {
		(*list).tWait[i] = generateRandomWait();
	}
}

void viewList(List list) {
	int i = 0;
	printf("[");
	for (i = 0; i < MAXLISTA; i++) {
		if (i == MAXLISTA - 1) {
			printf("%d]", list.elements[i]);
		} else {
			printf("%d\t", list.elements[i]);
		}
	}
}

void refreshList(List * list) {
	int i = 0;
	for (i = 0; i < MAXLISTA; i++) {
		if (i == MAXLISTA - 1) {
			(*list).elements[i] = generateRandom();
		} else {
			(*list).elements[i] = (*list).elements[i + 1];
		}
	}
}

void trace(List list, int threadId) {
	printf("\nThread: %d\t Valor: %d\t", threadId, (int) list.elements[0]);
	viewList(list);
}

int generateRandom(void) {
	return (rand() % 20);
}

int generateRandomWait(void) {
	return (rand() % 5) + 1;
}
